package com.hyperfix.washer.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.hyperfix.models.common.R;
import com.hyperfix.models.washer.dtos.RecordDTO;
import com.hyperfix.models.washer.vos.RecordQueryVO;
import com.hyperfix.washer.service.RecordService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.Min;

/**
 * @author JiangChunYu
 * 2024/4/4
 */
@RestController
@RequestMapping("/record")
public class RecordController {
    @Resource
    private RecordService recordService;

    /**
     * 查询历史监测数据
     *
     * @param pageNum       页码
     * @param size          大小
     * @param recordQueryVO 记录查询 VO
     * @return {@link R}<{@link IPage}<{@link RecordDTO}>> 查询结果
     */
    @PostMapping("/list/{pageNum}/{size}")
    public R<IPage<RecordDTO>> list(@PathVariable @Min(value = 1, message = "页号最小不能小于1") Integer pageNum,
                                    @PathVariable @Min(value = 1, message = "页大小最小不能小于1") Integer size,
                                    @RequestBody @Validated RecordQueryVO recordQueryVO) {
        IPage<RecordDTO> recordDTOIPage = recordService.list(pageNum, size, recordQueryVO);
        return R.success(recordDTOIPage);
    }

    /**
     * 导出历史数据Excel
     *
     * @param recordQueryVO 历史数据查询 VO
     * @param response      响应
     */
    @PostMapping("/exportExcel")
    public void exportExcel(@RequestBody @Validated RecordQueryVO recordQueryVO,
                            HttpServletResponse response) {
        recordService.exportExcel(recordQueryVO, response);
    }
}
